package com.example.shopping.authority.mapper;

import com.example.shopping.authority.entity.Cart;
import com.example.shopping.authority.entity.Shipping;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper {
    //查询商品所有商品
    @Select("select * from cart where userid=#{userid}")
    List<Cart> getCartList(@Param("userid")int userid);

    //修改购物车商品   参数(数量，状态，id)
    @Update("UPDATE cart set quantity=#{quantity},checked=#{checked} WHERE id=#{id};")
    int getCartUpdate(@Param("quantity")int quantity,@Param("checked")int checked,@Param("id")int id);

    //删除一个购物车商品
    @Delete("DELETE FROM cart WHERE Id=#{id};")
    int getCartDel(@Param("id")int id);

    //添加一个订单
    @Insert("INSERT into orders (userid,productid,quantity,postage,payment,`status`,paymenttype) value(#{userid},#{productid},#{quantity},#{postage},#{payment},#{status},#{paymenttype});")
    int getCartAddOrders(@Param("userid")int userid,@Param("productid")int productid,@Param("quantity")int quantity,@Param("postage")int postage,@Param("payment")int payment,@Param("status")int status,@Param("paymenttype")int paymenttype);

    //清空购物车所有商品
    @Delete("delete from cart where checked=1;")
    int getCartAllDel();

    //查找默认地址
    @Select("select * from shipping where userId=#{userId} and dfault=1 and isdel=0 or Id=20;")
    List<Shipping> getCartShipping(@Param("userId")int userId,@Param("Id")int Id);
}
